package com.system.FinancialDepartment.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.system.FinancialDepartment.dao.PerformanceRepository;
import com.system.FinancialDepartment.entity.Performance;

@Service
@Transactional
public class PerformanceService implements IPerformanceService {

	@Autowired
	private PerformanceRepository performanceRepository;
	
	@Override
	public void saveOrUpdate(Performance performance) {
		if(null!=performance.getId()) {
			performanceRepository.updatePerformance(performance.getId(),performance.getEmpId(),performance.getWage());
		}else {
			performanceRepository.save(performance);
		}
	}

	@Override
	public void delete(Performance performance) {
		performanceRepository.delete(performance);
	}

	@Override
	public Performance findOne(Long id) {
		return performanceRepository.findById(id);
	}

	@Override
	public List<Performance> findAll() {
		return (List<Performance>) performanceRepository.findAll();
	}

	@Override
	public int saveOrUpdate(Long id, Long empId, Long totalscore, Long wage) {
		return performanceRepository.updatePerformance(id, empId, wage);
	}

	@Override
	public int deletePerformances(Long[] ids) {
		return performanceRepository.deletePerformances(ids);
	}

	@Override
	public Page<Performance> findAll(Long empId, Pageable pageable) {
		return performanceRepository.findAll(empId, pageable);
	}

}
